package org.raphets.todayinhistory.utils;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.BaseAdapter;

public abstract class AdapterBase<T> extends BaseAdapter implements List<T>{
	public Activity mContext;
	
	
	public AdapterBase(Activity context) {
		super();
		mContext = context;
	}

	private  List<T> mList = new ArrayList<T>();
	
	public List<T> getList(){
		return mList;
	}
	public void setData(List<T> t){
		mList = t;
	}
	
	public void appendToList(List<T> list) {
		if (list == null) {
			return;
		}
		mList.addAll(list);
		notifyDataSetChanged();
	}

	public void appendToTopList(List<T> list) {
		if (list == null) {
			return;
		}
		mList.addAll(0, list);
		notifyDataSetChanged();
	}

	public void clear() {
		mList.clear();
		notifyDataSetChanged();
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	@Override
	public T getItem(int position) {
		// TODO Auto-generated method stub
		if(position > mList.size()-1){
			return null;
		}
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	@Override
	public void add(int location, T object) {
		mList.add(location, object);
	}
	@Override
	public boolean add(T object) {
		return mList.add(object);
	}
	@Override
	public boolean addAll(int location, Collection<? extends T> collection) {
		return mList.addAll(location, collection);
	}
	@Override
	public boolean addAll(Collection<? extends T> collection) {
		// TODO Auto-generated method stub
		return mList.addAll(collection);
	}
	@Override
	public boolean contains(Object object) {
		// TODO Auto-generated method stub
		return mList.contains(object);
	}
	@Override
	public boolean containsAll(Collection<?> collection) {
		// TODO Auto-generated method stub
		return mList.containsAll(collection);
	}
	@Override
	public T get(int location) {
		// TODO Auto-generated method stub
		return mList.get(location);
	}
	@Override
	public int indexOf(Object object) {
		// TODO Auto-generated method stub
		return mList.indexOf(object);
	}
	@Override
	public Iterator<T> iterator() {
		// TODO Auto-generated method stub
		return mList.iterator();
	}
	@Override
	public int lastIndexOf(Object object) {
		// TODO Auto-generated method stub
		return mList.lastIndexOf(object);
	}
	@Override
	public ListIterator<T> listIterator() {
		// TODO Auto-generated method stub
		return mList.listIterator();
	}
	@Override
	public ListIterator<T> listIterator(int location) {
		// TODO Auto-generated method stub
		return mList.listIterator(location);
	}
	@Override
	public T remove(int location) {
		// TODO Auto-generated method stub
		return mList.remove(location);
	}
	@Override
	public boolean remove(Object object) {
		// TODO Auto-generated method stub
		return mList.remove(object);
	}
	@Override
	public boolean removeAll(Collection<?> collection) {
		// TODO Auto-generated method stub
		return mList.removeAll(collection);
	}
	@Override
	public boolean retainAll(Collection<?> collection) {
		// TODO Auto-generated method stub
		return mList.retainAll(collection);
	}
	@Override
	public T set(int location, T object) {
		// TODO Auto-generated method stub
		return mList.set(location, object);
	}
	@Override
	public int size() {
		// TODO Auto-generated method stub
		return mList.size();
	}
	@Override
	public List<T> subList(int start, int end) {
		// TODO Auto-generated method stub
		return mList.subList(start, end);
	}
	@Override
	public Object[] toArray() {
		// TODO Auto-generated method stub
		return mList.toArray();
	}
	@Override
	public <T> T[] toArray(T[] array) {
		// TODO Auto-generated method stub
		return mList.toArray(array);
	}
	public final <E extends View> E getView(View parent, int id) {
		try {
			return (E) parent.findViewById(id);
		} catch (ClassCastException ex) {
			Log.e("通过父类布局初始化化控件", "类转型异常", ex);
			throw ex;
		}
	}
}
